package com.fulin.leetcode;

/**
 * 两两翻转链表的节点
 *
 * @Author fulin
 * @Date 2022/9/14 17:41
 **/
public class Num24 {
    public ListNode swapPairs(ListNode head) {
        if(head == null || head.next == null) return head;
        ListNode dummy = new ListNode(0,head);
        ListNode left = dummy;
        while(left.next != null && left.next.next != null){
            ListNode mid = left.next;
            ListNode right = left.next.next;
            left.next = right;
            mid.next = right.next;
            right.next = mid;
            left = mid;
        }
        return dummy.next;
    }
}
